﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using DAOBase;
using Interfaces;

namespace Interview_Prov
{
    public class InterviewRoleProvider : RoleProvider
    {
        private DaoFacade facade;
        private IRoleDAO roleDao;
        private IUserDAO userDao;

        public InterviewRoleProvider()
            : base()
        {
            this.facade = new DaoFacade();
            this.roleDao = this.facade.GetFactory().GetRoleDAO();
            this.userDao = this.facade.GetFactory().GetUserDAO();
        }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            this.roleDao.CreateRole(roleName);
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            this.roleDao.DeleteRole(this.roleDao.GetRoleID(roleName));
            return true;
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            return this.roleDao.GetRolesList().Select((x) => (x.Value)).ToArray();
        }

        public override string[] GetRolesForUser(string username)
        {
            return this.userDao.GetUser(userDao.GetUserID(username)).Roles.ToArray();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            return this.userDao.GetUsersForRole(roleName, 0).Select((x) => (x.Login)).ToArray();
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            return this.userDao.GetUser(userDao.GetUserID(username)).Roles.Contains(roleName);
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            return this.roleDao.RoleExists(roleName);
        }
    }
}